class Solution(object):
    def peopleIndexes(self, favoriteCompanies):
        st = [[set(f), index] for index, f in enumerate(favoriteCompanies)]
        st.sort(key=lambda x: -len(x[0]))
        out = []
        for id, (f, _) in enumerate(st):
            flag = True
            for index in out:
                if not f - st[index][0]:
                    flag = False
                    break
            if flag:
                out.append(id)
        out = [st[id][1] for id in out]
        out.sort()
        return out


data = Solution()
favoriteCompanies = [["nxaqhyoprhlhvhyojanr", "ovqdyfqmlpxapbjwtssm", "qmsbphxzmnvflrwyvxlc", "udfuxjdxkxwqnqvgjjsp",
                      "yawoixzhsdkaaauramvg", "zycidpyopumzgdpamnty"],
                     ["nxaqhyoprhlhvhyojanr", "ovqdyfqmlpxapbjwtssm", "udfuxjdxkxwqnqvgjjsp", "yawoixzhsdkaaauramvg",
                      "zycidpyopumzgdpamnty"],
                     ["ovqdyfqmlpxapbjwtssm", "qmsbphxzmnvflrwyvxlc", "udfuxjdxkxwqnqvgjjsp", "yawoixzhsdkaaauramvg",
                      "zycidpyopumzgdpamnty"]]
print(data.peopleIndexes(favoriteCompanies))
